package day16;

import java.util.ArrayList;
import java.util.List;

public abstract class News {
    String name;
    public abstract void Notice(String msg);
}

class Reader extends News{
    public Reader(String name){
        super.name=name;
    }
    public void Notice(String msg) {
        System.out.println(name+"收到了新的新闻:"+msg+name+"还发来了贺电！");
    }
}
interface ReaderToic{
    void Focus(Reader user);
    void Notice(String msg);
}

class NewsPublisher implements ReaderToic{
    private List<Reader> list=new ArrayList<>();
    @Override
    public void Focus(Reader user) {
        list.add(user);
        System.out.println(user.name+"关注了新闻平台！");
    }

    @Override
    public void Notice(String msg) {
         System.out.println("发布了新的新闻！"+msg);
         for (Reader r:list){
             r.Notice(msg);
         }
    }

    public static void main(String[] args) {
        NewsPublisher np=new NewsPublisher();
        News news1=new Reader("茜茜");
        News news2=new Reader("星星");
        News news3=new Reader("小月亮");
        np.Focus((Reader) news1);
        np.Focus((Reader) news2);
        np.Focus((Reader) news3);
        np.Notice("号外号外，小日本发生大地震，小日本都嘎啦！");

    }
}